package com.vzoom.logdesensitization.strategyimpl;

import com.vzoom.logdesensitization.DesensitizationStrategy;
import com.vzoom.logdesensitization.util.StarUtil;

public class IdCardDesensitizationStrategy implements DesensitizationStrategy {
    @Override
    public String desensitization(Object origin) {
        String toString = String.valueOf(origin);
        if (origin == null) {
            return toString;
        }
        int length = toString.length();
        if (length == 15 || length == 18) {
            return toString.substring(0, 4) + StarUtil.getStar(length - 12) + toString.substring(length - 8, length);
        }
        return toString;
    }
}
